package git.soulbgm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import git.soulbgm.config.SysConfig;
import git.soulbgm.pojo.*;
import git.soulbgm.service.*;
import org.springframework.stereotype.Service;
import git.soulbgm.mapper.NodeStatusMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 监控客户端状态表
 *
 * @author SoulBGM
 * @date 2020-11-18 10:03:05
 */
@Service
public class NodeStatusServiceImpl extends ServiceImpl<NodeStatusMapper, NodeStatus> implements NodeStatusService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean reset(List<NodeStatus> list) {
        remove(new LambdaQueryWrapper<NodeStatus>().eq(NodeStatus::getRegionCode, SysConfig.getConfig().getRegionCode()));
        return saveBatch(list);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean reset(NodeStatus status) {
        remove(new LambdaQueryWrapper<NodeStatus>().eq(NodeStatus::getId, status.getId()));
        return save(status);
    }

}